package com.example.blmap;

import android.content.Context;
import android.database.DataSetObservable;
import android.database.DataSetObserver;

import com.example.locat.BeacoNode;
import com.example.locat.abs.Point;

import java.util.ArrayList;
import java.util.List;

public class BlMapAdapter extends DataSetObserver {

    private Context context;

    private List<Beacon> beacons = new ArrayList<>();
    private List<Revicer> revicers = new ArrayList<>();

    private DataSetObservable mObservable = new DataSetObservable();

    public BlMapAdapter(Context context){
        this.context = context;
    }

    public void addBeacon(Beacon beacon){
        beacons.add(beacon);
    }

    public void addBeacon(BeacoNode node){
        Beacon beacon = new Beacon();
        beacon.setLocation(node.getPoint());
        beacon.setLength((int)node.getDistence());
        beacon.setUuid(node.getUUID());
        beacon.setName(node.getMajor()+"-"+node.getMinor());
        beacon.setMacAddress(node.getMacAddress());
        beacons.add(beacon);
    }

    public void addRevicer(Revicer revicer){
        revicers.add(revicer);
    }

    public void clearBeacon(){
        beacons.clear();
    }

    public void clearRevicer(){
        revicers.clear();
    }

    public int getBeaconCount(){
        return beacons == null ? 0 : beacons.size();
    }

    public int getRevicerCount(){
        return revicers == null ? 0 : revicers.size();
    }


    public List<Beacon> getBeacons(){
        if(beacons != null){
            return beacons;
        }
        return null;
    }
    public List<Revicer> getRevicers(){
        if(revicers != null){
            return revicers;
        }
        return null;
    }

    public void registerDataSetObserver(DataSetObserver observer){
        mObservable.registerObserver(observer);
    }

    public void unregisterDataSetObserver(DataSetObserver observer){
        mObservable.unregisterObserver(observer);
    }

    public void notifyDataSetChanged() {
        mObservable.notifyChanged();
    }
}
